import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '服务名称',
    dataIndex: 'serverName',
    width: 200,
  },
  {
    title: '服务类型',
    dataIndex: 'serverType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const serverType = record.serverType;
      const color = serverType == 1 ? 'green' : 'orange';
      const text = serverType == 1 ? '基础服务' : '特殊服务';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '特殊服务类型',
    dataIndex: 'serverCode',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const serverCodeArray = [
        { label: '贵宾服务', value: 'vipServer' },
        { label: '电子金', value: 'money' },
        { label: '高铁电子金', value: 'highSpeedMoney' },
        { label: '接送机', value: 'transfer' },
        { label: '酒店金', value: 'hotel' },
        { label: '旅游金', value: 'tourism' },
        { label: '机票金', value: 'ticket' },
        { label: '延误保障', value: 'delayrisk' },
        { label: '积分', value: 'integral' },
        { label: '通用', value: 'common' },
      ];
      const serverCode: any = serverCodeArray.find((item) => item.value == record.serverCode);
      if (serverCode) {
        return serverCode.label;
      }
      return '无';
    },
  },
  {
    title: '服务图标',
    dataIndex: 'serverImg',
    width: 70,
    customRender: render.renderImage,
  },

  {
    title: '排序',
    dataIndex: 'serverSort',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 200,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'serverName',
    label: '服务名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'serverType',
    label: '服务类型',
    component: 'Select',
    colProps: { span: 8 },
    componentProps: {
      options: [
        { label: '基础服务', value: 1 },
        { label: '特殊服务', value: 2 },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '主键',
    field: 'serverId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '服务名称',
    field: 'serverName',
    component: 'Input',
    required: true,
  },
  {
    label: '服务类型',
    field: 'serverType',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '基础服务', value: 1 },
          { label: '特殊服务', value: 2 },
        ],
        onChange(serverType) {
          formModel.serverCode = '';
        },
      };
    },
  },
  {
    label: '特殊服务类型',
    field: 'serverCode',
    component: 'Select',
    required: true,
    defaultValue: 'common',
    componentProps: {
      options: [
        { label: '贵宾服务', value: 'vipServer' },
        { label: '电子金', value: 'money' },
        { label: '高铁电子金', value: 'highSpeedMoney' },
        { label: '接送机', value: 'transfer' },
        { label: '酒店金', value: 'hotel' },
        { label: '旅游金', value: 'tourism' },
        { label: '机票金', value: 'ticket' },
        { label: '延误保障', value: 'delayrisk' },
        { label: '积分', value: 'integral' },
        { label: '通用', value: 'common' },
      ],
    },
    ifShow: ({ model }) => {
      if (model.serverType == 2) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '排序',
    field: 'serverSort',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '服务图标',
    field: 'serverImg',
    component: 'ImageUpload',
  },
];
